DOC=../doc
BIN=../bin
SOURCE=.
BUILD=../build
CLIENT_OBJECTS=$(BUILD)/transfer_clnt.o $(BUILD)/transfer_xdr.o $(BUILD)/paperclient.o $(BUILD)/helper.o
SERVER_OBJECTS=$(BUILD)/transfer_svc.o $(BUILD)/transfer_xdr.o $(BUILD)/paperserver.o $(BUILD)/papers.o $(BUILD)/helper.o
TEST_OBJECTS=$(BUILD)/test.o $(BUILD)/papers.o $(BUILD)/helper.o
HOTELGWCLIENT_OBJECTS=$(BUILD)/hotelgwclient.o $(BUILD)/network.o
RPC_FILES=$(SOURCE)/transfer_clnt.c $(SOURCE)/transfer_xdr.c $(SOURCE)/transfer_svc.c $(SOURCE)/transfer.h
PROGRAMS=$(BIN)/paperclient $(BIN)/paperserver $(BIN)/test $(BIN)/hotelgwclient

CC=gcc
LINKER=gcc
COPTS=-Wall
LOPTS=-Wall -lnsl

all: $(BUILD) $(BIN) $(PROGRAMS) 

lint:
	split $(src)/*.h
	split $(src)/*.c

package:
	tar -cf ../marek.kirejczyk.tar $(SOURCE) 

$(BUILD):
	mkdir $(BUILD)

$(BIN):
	mkdir $(BIN)

$(BIN)/paperclient: $(CLIENT_OBJECTS)
	$(LINKER) $(LOPTS)  $^ -o $@ 

$(BIN)/paperserver: $(SERVER_OBJECTS)
	$(LINKER) $(LOPTS) $^ -o $@

$(BIN)/test: $(TEST_OBJECTS)
	$(LINKER) $(LOPTS) $^ -o $@

$(BIN)/hotelgwclient: $(HOTELGWCLIENT_OBJECTS)
	$(LINKER) $(LOPTS) $^ -o $@


clean:
	rm -f $(RPC_FILES) $(CLIENT_OBJECTS) $(SERVER_OBJECTS) $(TEST_OBJECTS) $(PROGRAMS) $(HOTELGWCLIENT_OBJECTS)


$(BUILD)/%.o: $(SOURCE)/%.c $(SOURCE)/%.h
	$(CC) $(COPTS) -c $(SOURCE)/$*.c -o $@

$(BUILD)/%.o: $(SOURCE)/%.c 
	$(CC) $(COPTS) -c $^ -o $@


$(RPC_FILES): $(SOURCE)/transfer.x consts.h
	rpcgen $(SOURCE)/transfer.x

